<?php
 
header("Content-type: text/html; charset=utf-8");
 
// 获取用户输入和选择的
$username=$_POST['username'];
$date=$_POST['time'];
$message = $_POST['message'];
 
// 数据库数据
$servername = "localhost";
$name = "root";
$password = "root";
$dbname = "login";
 
$conn = mysqli_connect($servername, $name, $password, $dbname);
if(! $conn )
{
    die('连接失败: ' . mysqli_error($conn));
}

$sql = "insert into messages 
        values ('$username','$date','$message')";

$result = mysqli_query($conn, $sql );

if ($result) {
  echo "<script> alert('留言成功');parent.location.href='/blogger/message.html'; </script>";
} else {
  echo "<script> alert('留言失败');parent.location.href='/blogger/message.html'; </script>" . $sql . "<br>" . $conn->error;
}
 
// 关闭数据库
$conn->close();
 
?>



